import 'package:flutter/material.dart';

void main() {
  runApp(
    MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: Text("你好Flutter")),
        body: Column(
          children: [
            MyApp(), // 使用自定义的MyApp组件
            // SizedBox(height: 20), // 添加间距
            // Circular(), // 使用自定义的Circular组件
            // SizedBox(height: 20), // 添加间距
            // ClipImage(),
            SizedBox(height: 20), // 添加间距
            LocalImage(), // 使用自定义的LocalImage组件
          ],
        ),
      ),
    ),
  );
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Container(
        width: 150,
        height: 150,
        margin: EdgeInsets.fromLTRB(0, 40, 0, 0),
        decoration: BoxDecoration(color: Colors.yellow),
        // https://www.itying.com/images/201906/goods_img/1120_P_1560842352183.png
        // https://www.itying.com/themes/itying/images/ionic4.png
        child: Image.network(
          "https://www.itying.com/themes/itying/images/ionic4.png",
          // scale: 2,
          // alignment: Alignment.centerLeft,
          // fit: BoxFit.cover, // 设置图片填充方式为cover
          // repeat: ImageRepeat.repeatY,
        ),
      ),
    ); // 使用Center组件包裹Text组件
  }
}

// 实现一个圆形图片
class Circular extends StatelessWidget {
  const Circular({super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      width: 150,
      height: 150,
      decoration: BoxDecoration(
        color: Colors.yellow,
        borderRadius: BorderRadius.circular(75), // 设置圆角半径为75，形成圆形
        image: DecorationImage(
          image: NetworkImage(
            "https://www.itying.com/themes/itying/images/ionic4.png",
          ),
          fit: BoxFit.cover, // 设置图片填充方式为cover
        ),
      ),
    );
  }
}

// 实现一个圆形图片 使用ClipOval组件包裹Image.network
class ClipImage extends StatelessWidget {
  const ClipImage({super.key});

  @override
  Widget build(BuildContext context) {
    return ClipOval(
      child: Image.network(
        "https://www.itying.com/themes/itying/images/ionic4.png",
        width: 150,
        height: 150,
        fit: BoxFit.cover, // 设置图片填充方式为cover
      ),
    );
  }
}

// 实现一个本地图片组件
class LocalImage extends StatelessWidget {
  const LocalImage({super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      width: 150,
      height: 150,
      decoration: BoxDecoration(
        color: Colors.yellow,
        // borderRadius: BorderRadius.circular(75), // 设置圆角半径为75，形成圆形
      ),
      child: Image.asset("images/a.jpeg", fit: BoxFit.cover),
    );
  }
}
